package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserOfficialAccount;
import com.happy.cat.project.system.service.IUserOfficialAccountService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 用户粉丝、关注Controller
 *
 * @author verne
 * @date 2020-09-03
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userOfficialAccount" )
@Api("用户粉丝、关注 API")
public class UserOfficialAccountController extends BaseController {

    private final IUserOfficialAccountService iUserOfficialAccountService;

    /**
     * 查询用户粉丝、关注列表
     */
    @ApiOperation(value = "查询用户粉丝、关注列表",notes = "查询用户粉丝、关注列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userOfficialAccount:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserOfficialAccount userOfficialAccount)
    {
        startPage();
        LambdaQueryWrapper<UserOfficialAccount> lqw = new LambdaQueryWrapper<UserOfficialAccount>();
        if (userOfficialAccount.getFocusType() != null){
            lqw.eq(UserOfficialAccount::getFocusType ,userOfficialAccount.getFocusType());
        }
        if (userOfficialAccount.getAccountId() != null){
            lqw.eq(UserOfficialAccount::getAccountId ,userOfficialAccount.getAccountId());
        }
        if (userOfficialAccount.getFocusId() != null){
            lqw.eq(UserOfficialAccount::getFocusId ,userOfficialAccount.getFocusId());
        }
        List<UserOfficialAccount> list = iUserOfficialAccountService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户粉丝、关注列表
     */
    @ApiOperation(value = "导出用户粉丝、关注列表",notes = "导出用户粉丝、关注列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOfficialAccount:export')" )
    @Log(title = "用户粉丝、关注" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserOfficialAccount userOfficialAccount) {
        LambdaQueryWrapper<UserOfficialAccount> lqw = new LambdaQueryWrapper<UserOfficialAccount>(userOfficialAccount);
        List<UserOfficialAccount> list = iUserOfficialAccountService.list(lqw);
        ExcelUtil<UserOfficialAccount> util = new ExcelUtil<UserOfficialAccount>(UserOfficialAccount. class);
        return util.exportExcel(list, "userOfficialAccount" );
    }

    /**
     * 获取用户粉丝、关注详细信息
     */
    @ApiOperation(value = "获取用户粉丝、关注详细信息",notes = "获取用户粉丝、关注详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOfficialAccount:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserOfficialAccountService.getById(id));
    }

    /**
     * 新增用户粉丝、关注
     */
    @ApiOperation(value = "新增用户粉丝、关注",notes = "新增用户粉丝、关注",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOfficialAccount:add')" )
    @Log(title = "用户粉丝、关注" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserOfficialAccount userOfficialAccount) {
        return toAjax(iUserOfficialAccountService.save(userOfficialAccount) ? 1 : 0);
    }

    /**
     * 修改用户粉丝、关注
     */
    @ApiOperation(value = "修改用户粉丝、关注",notes = "修改用户粉丝、关注",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOfficialAccount:edit')" )
    @Log(title = "用户粉丝、关注" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserOfficialAccount userOfficialAccount) {
        return toAjax(iUserOfficialAccountService.updateById(userOfficialAccount) ? 1 : 0);
    }

    /**
     * 删除用户粉丝、关注
     */
    @ApiOperation(value = "删除用户粉丝、关注",notes = "删除用户粉丝、关注",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOfficialAccount:remove')" )
    @Log(title = "用户粉丝、关注" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserOfficialAccountService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
